﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Super_Pong.BaseClasses
{
    class simple_controler
    {
        Keys key;
        bool pressed;
        bool trava = false;
        public enum Behavior { NORMAL, DETECT_INITIAL_PRESS_ONLY }
        private Behavior behavior;

        public simple_controler(Keys key)
        {
            this.key = key;
            pressed = false;
            behavior = Behavior.NORMAL;
        }

        public simple_controler(Keys key, Behavior b)
        {
            this.key = key;
            pressed = false;
            behavior = b;
        }

        public void reassign(Keys k)
        {
            this.key = k;
        }

        public void tap()
        {
            press();
            release();

        }

        public void press()
        {
            pressed = true;
        }

        public void release()
        {
            pressed = false;
        }

        public bool isPressed()
        {
            return pressed;
        }

        public void update(KeyboardState keyboard)
        {
            #region NORMAL BEHAVIOR
            if(keyboard.IsKeyDown(key) && behavior == Behavior.NORMAL){
                press();
            }

            if (keyboard.IsKeyUp(key) && behavior == Behavior.NORMAL)
            {
                release();
            }
            #endregion

            #region DETECT_INITIAL_PRESS_ONLY
            if(keyboard.IsKeyDown(key) && behavior == Behavior.DETECT_INITIAL_PRESS_ONLY && !trava){
                tap();
                trava = true;
            }

            if (keyboard.IsKeyUp(key) && behavior == Behavior.DETECT_INITIAL_PRESS_ONLY && trava)
            {
                trava = false;
            }
            #endregion
        }
    }
}
